/**
 * Copyright (C) 2010, 2011 Neofonie GmbH
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.dicodeproject.blogimport.filereader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Counter object for count and log imported documents.
 * 
 * @author claude
 * 
 */
public class ImportCounter {

	private static final Logger LOG = LoggerFactory.getLogger(ImportCounter.class);

	private int counter = 0;

	private int frequency = 100;

	/**
	 * Add a referenced amount to the counter.
	 * 
	 * @param number
	 *            the amount to add
	 */
	public void count(final int number) {
		this.counter += number;
	}

	/**
	 * Resets the internal counter to 0.
	 */
	public void reset() {
		this.counter = 0;
	}

	/**
	 * This method returns the internal counter.
	 * 
	 * @return the internal counter
	 */
	public int getCounter() {
		return this.counter;
	}

	/**
	 * Returns the internal frequency that defines the state for the logCounter
	 * method.
	 * 
	 * @return the internal frequency
	 */
	public int getFrequency() {
		return this.frequency;
	}

	/**
	 * This method is a helper for printing the current counter in log4j.
	 * 
	 * @param state
	 */
	public void logCounter(boolean state) {
		if (LOG.isInfoEnabled() && state) {
			LOG.info("Documents (total " + this.counter + " documents so far).");
		}
	}

}
